package com.cta.entity;

import java.util.List;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.cta.constant.AreaCodeType;

@Entity
@Table(name = "cta_tariff_area_code")
public class TariffAreaCode implements BaseEntity {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cta_tariff_area_code_seq")
	@SequenceGenerator(name = "cta_tariff_area_code_seq", sequenceName = "cta_tariff_area_code_seq")
	@Column(name = "id", unique = true, nullable = false)
	private Long id;

	@Column(name = "area_code", nullable = false)
	private String areaCode;
	
	@Column(name = "name", nullable = true)
	private String name;
	
	@Column(name = "description", nullable = true)
	private String description;
	
	@Column(name = "type", nullable = false)
	@Enumerated(EnumType.STRING)
	private AreaCodeType type;

	@Column(name = "parent_area_code_id", nullable = true)
	private Long parentAreaCodeId;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "tariff_group_id", nullable = false)
	private TariffGroup tariffGroup;
	
	@OneToMany(fetch =  FetchType.LAZY)
	@JoinColumn(name = "tariff_areacode_id")
	private List<AreaCodeRate> areaCodeRates;
	
	//custom field
	@Transient
	private List<Map<String, String>> templateCodes;

	public TariffAreaCode() {
	}

	public TariffAreaCode(String name) {
		this.name = name;
	}

	public TariffAreaCode(String name, String areaCode, Long tariffGroupId) {
		this.name = name;
		this.areaCode = areaCode;
		this.tariffGroup = new TariffGroup(tariffGroupId);
		this.type = AreaCodeType.AREACODE;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public TariffGroup getTariffGroup() {
		return tariffGroup;
	}

	public void setTariffGroup(TariffGroup tariffGroup) {
		this.tariffGroup = tariffGroup;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public AreaCodeType getType() {
		return type;
	}

	public void setType(AreaCodeType type) {
		this.type = type;
	}

	public String getAreaCode() {
		return areaCode;
	}

	public void setAreaCode(String areaCode) {
		this.areaCode = areaCode;
	}

	public List<AreaCodeRate> getAreaCodeRates() {
		return areaCodeRates;
	}

	public void setAreaCodeRates(List<AreaCodeRate> areaCodeRates) {
		this.areaCodeRates = areaCodeRates;
	}

	public List<Map<String, String>> getTemplateCodes() {
		return templateCodes;
	}

	public void setTemplateCodes(List<Map<String, String>> templateCodes) {
		this.templateCodes = templateCodes;
	}

	public Long getParentAreaCodeId() {
		return parentAreaCodeId;
	}

	public void setParentAreaCodeId(Long parentAreaCodeId) {
		this.parentAreaCodeId = parentAreaCodeId;
	}


}
